﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Host;
using System.Threading;
using System.Management.Automation;
using System.Collections.ObjectModel;
using System.Security;
using System.Text.RegularExpressions;

namespace Decav.Web.PowerShell
{
    public class WebHttpRequestHost : PSHost
    {
        private PowershellWebUserInterface _ui;
        private Guid _instanceId;
        private HttpContext _context;

        public WebHttpRequestHost(HttpContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            _context = context;
            _instanceId = Guid.NewGuid();
            _ui = new PowershellWebUserInterface(context);
        }

        public override System.Globalization.CultureInfo CurrentCulture
        {
            get { return Thread.CurrentThread.CurrentCulture; }
        }

        public override System.Globalization.CultureInfo CurrentUICulture
        {
            get { return Thread.CurrentThread.CurrentUICulture; }
        }

        public override void EnterNestedPrompt()
        {
        }

        public override void ExitNestedPrompt()
        {
        }

        public override Guid InstanceId
        {
            get
            {
                return _instanceId;
            }
        }

        public override string Name
        {
            get
            {
                return "PowerShellHttpHandler";
            }
        }

        public override void NotifyBeginApplication()
        {
        }

        public override void NotifyEndApplication()
        {
        }

        public override void SetShouldExit(int exitCode)
        {
        }

        public override PSHostUserInterface UI
        {
            get
            {
                return _ui;
            }
        }

        public override Version Version
        {
            get
            {
                return new Version("1.0.0.0");
            }
        }
    }
}
